package com.cloudsigns.factorymanager2.project.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.produce.adapter.Produce_ProductInfoAdapter;
import com.cloudsigns.factorymanager2.produce.bean.ProduceProduceOrderBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.DateUtil;

public class ProduceOrderDetailActivity extends BaseActivity {
    private String TAG = ProduceOrderDetailActivity.class.getSimpleName();
    private RelativeLayout rl_back;
    private TextView tv_title;
    private TextView edt_project_name, edt_engineering_name, edt_order_type, edt_order_level, edt_completion_date;
    private CheckBox cb_isHurry;
    private ListView lv;
    private ProduceProduceOrderBean produceOrderBean;

    private Produce_ProductInfoAdapter adapter;

    @Override
    protected void onBaseCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_produce_order_detail);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        edt_project_name = findViewById(R.id.edt_project_name);
        edt_engineering_name = findViewById(R.id.edt_engineering_name);
        edt_order_type = findViewById(R.id.edt_order_type);
        edt_order_level = findViewById(R.id.edt_order_level);
        edt_completion_date = findViewById(R.id.edt_completion_date);
        cb_isHurry = findViewById(R.id.cb_isHurry);
        lv = findViewById(R.id.lv);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tv_title.setText("生产任务单");
        Intent intent = getIntent();
        if (null != intent) {
            produceOrderBean = (ProduceProduceOrderBean) intent.getSerializableExtra(ConstantUtil.KEY_1);
        }

        edt_project_name.setText(produceOrderBean.getProjectName());
        edt_engineering_name.setText(produceOrderBean.getEngineeringName());
        edt_order_type.setText(produceOrderBean.getType());
        edt_completion_date.setText(DateUtil.getYyyy_Mm_Dd(produceOrderBean.getCompleteDate()));

        CommonEnum.ProduceOrderLevel level = produceOrderBean.getLevel();
        if (null != level) {
            if (produceOrderBean.getLevel() == CommonEnum.ProduceOrderLevel.VERY_IMPORTANT) {
                edt_order_level.setText("一级");
            } else if (produceOrderBean.getLevel() == CommonEnum.ProduceOrderLevel.MORE_IMPORTANT) {
                edt_order_level.setText("二级");
            } else if (produceOrderBean.getLevel() == CommonEnum.ProduceOrderLevel.GENERALLY_IMPORTANT) {
                edt_order_level.setText("三级");
            } else if (produceOrderBean.getLevel() == CommonEnum.ProduceOrderLevel.NORMAL) {
                edt_order_level.setText("四级");
            }
        }

        CommonEnum.ProduceOrderIsHurry isHurry = produceOrderBean.getIsHurry();
        if (null != isHurry) {
            if (produceOrderBean.getIsHurry() == CommonEnum.ProduceOrderIsHurry.HURRY) {
                cb_isHurry.setChecked(true);
            } else if (produceOrderBean.getIsHurry() == CommonEnum.ProduceOrderIsHurry.NOT_HURRY) {
                cb_isHurry.setChecked(false);
            }
        }

        adapter = new Produce_ProductInfoAdapter(this, TAG);
        adapter.setData(produceOrderBean.getProductList());
        lv.setAdapter(adapter);
        adapter.notifyDataSetChanged();

    }

    @Override
    public void setListener() {
        rl_back.setOnClickListener(this);
    }

    @Override
    public void widgetClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
        }
    }
}
